﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using Tools;
using Tour.DAL;

namespace Tour.BLL
{
    /// <summary>
    /// Summary description for TblTourType
    /// </summary>
    public class TblTourTypeManagerBase
    {
        public TblTourTypeManagerBase()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void InsertUpdate(TblTourTypeEntity item)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", item.Id));
            ls.Add(new SqlParameter("@ParentId", item.ParentId));
            ls.Add(new SqlParameter("@LanguageId", item.LanguageId));
            ls.Add(new SqlParameter("@Name", item.Name));
            ls.Add(new SqlParameter("@TextId", item.TextId));
            ls.Add(new SqlParameter("@IsVisible", item.IsVisible));
            ls.Add(new SqlParameter("@DisplayOrder", item.DisplayOrder));
            ls.Add(new SqlParameter("@Title", item.Title));
            ls.Add(new SqlParameter("@Keywords", item.Keywords));
            ls.Add(new SqlParameter("@Description", item.Description));
            ls.Add(new SqlParameter("@CreatedBy", item.CreatedBy));
            ls.Add(new SqlParameter("@CreatedDate", item.CreatedDate));
            ls.Add(new SqlParameter("@UpdatedBy", item.UpdatedBy));
            ls.Add(new SqlParameter("@UpdatedDate", item.UpdatedDate));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblTourType", sqlparam);
        }
        public void InsertUpdate(int Id, int ParentId, int LanguageId, string Name, string TextId, bool IsVisible, int DisplayOrder, string Title, string Keywords, string Description, string CreatedBy, System.DateTime CreatedDate, string UpdatedBy, System.DateTime UpdatedDate)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            ls.Add(new SqlParameter("@ParentId", ParentId));
            ls.Add(new SqlParameter("@LanguageId", LanguageId));
            ls.Add(new SqlParameter("@Name", Name));
            ls.Add(new SqlParameter("@TextId", TextId));
            ls.Add(new SqlParameter("@IsVisible", IsVisible));
            ls.Add(new SqlParameter("@DisplayOrder", DisplayOrder));
            ls.Add(new SqlParameter("@Title", Title));
            ls.Add(new SqlParameter("@Keywords", Keywords));
            ls.Add(new SqlParameter("@Description", Description));
            ls.Add(new SqlParameter("@CreatedBy", CreatedBy));
            ls.Add(new SqlParameter("@CreatedDate", CreatedDate));
            ls.Add(new SqlParameter("@UpdatedBy", UpdatedBy));
            ls.Add(new SqlParameter("@UpdatedDate", UpdatedDate));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_InsertUpdateTblTourType", sqlparam);
        }
        public string GetUniqueTextIdFromUnicodeText(string UnicodeText)
        {
            string strSql = @"  SELECT TextId FROM TblTourType tn
                                WHERE tn.TextId=@TextId";
           string textId = WebUtility.GetUniqueTextIdFromUnicodeText(UnicodeText, "@TextId", strSql
               , SqlHelper.TourConnectString, 255);
           return textId;
        }
        public void Delete(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            SqlHelper.ExecuteNonQuery(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_DeleteTblTourType", sqlparam);
        }
        public TblTourTypeEntity GetTblTourTypeEntity(DataRow dr)
        {
            TblTourTypeEntity item = new TblTourTypeEntity();            
            if (dr.Table.Columns.Contains("Id"))
                item.Id = dr["Id"].ToInt();              
            if (dr.Table.Columns.Contains("ParentId"))
                item.ParentId = dr["ParentId"].ToInt();              
            if (dr.Table.Columns.Contains("LanguageId"))
                item.LanguageId = dr["LanguageId"].ToInt();              
            if (dr.Table.Columns.Contains("Name"))
                item.Name = dr["Name"].ToString();              
            if (dr.Table.Columns.Contains("TextId"))
                item.TextId = dr["TextId"].ToString();              
            if (dr.Table.Columns.Contains("IsVisible"))
                item.IsVisible = dr["IsVisible"].ToBoolean();              
            if (dr.Table.Columns.Contains("DisplayOrder"))
                item.DisplayOrder = dr["DisplayOrder"].ToInt();              
            if (dr.Table.Columns.Contains("Title"))
                item.Title = dr["Title"].ToString();              
            if (dr.Table.Columns.Contains("Keywords"))
                item.Keywords = dr["Keywords"].ToString();              
            if (dr.Table.Columns.Contains("Description"))
                item.Description = dr["Description"].ToString();              
            if (dr.Table.Columns.Contains("CreatedBy"))
                item.CreatedBy = dr["CreatedBy"].ToString();              
            if (dr.Table.Columns.Contains("CreatedDate"))
                item.CreatedDate = dr["CreatedDate"].ToString().ToDateTime("vi-VN");              
            if (dr.Table.Columns.Contains("UpdatedBy"))
                item.UpdatedBy = dr["UpdatedBy"].ToString();              
            if (dr.Table.Columns.Contains("UpdatedDate"))
                item.UpdatedDate = dr["UpdatedDate"].ToString().ToDateTime("vi-VN");              
            return item;
        }        
        public DataTable SelectOneRDT(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourType", sqlparam);
        }
        public TblTourTypeEntity SelectOne(int Id)
        {
            List<SqlParameter> ls = new List<SqlParameter>();
            ls.Add(new SqlParameter("@Id", Id));
            SqlParameter[] sqlparam = ls.ToArray();
            DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourType", sqlparam);
            if(dt!=null && dt.Rows.Count>0)
                return GetTblTourTypeEntity(dt.Rows[0]);
            return null;
        }
        public DataTable SelectAllRDT()
        {
            return SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourTypesAll", null);
        }
        public List<TblTourTypeEntity> SelectAll()
        {
            List<TblTourTypeEntity> lsresult= new List<TblTourTypeEntity>();
            DataTable dt =  SqlHelper.ExecuteDataTable(SqlHelper.TourConnectString, CommandType.StoredProcedure, "tr_SelectTblTourTypesAll", null);
            if (dt != null && dt.Rows.Count > 0)
                for (int i = 0; i < dt.Rows.Count; i++)
                    lsresult.Add(GetTblTourTypeEntity(dt.Rows[i]));            
            return lsresult;
        }
    }
}

